#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

void Find(int arr[], int sz, int* pnum1, int* pnum2)
{
	int tmp = 0;
	for (int i = 0; i < sz; i++)
	{
		tmp ^= arr[i];
	}
	int pos = -1;
	for (int i = 0; i < 32; i++)
	{
		if (tmp & 1 == 1)
		{
			pos = i;
			break;
			tmp = tmp >> 1; 
		}
	}
	for (int i = 0; i < sz; i++)
	{
		if ((arr[i] >> pos) & 1 == 1)
		{
			*pnum1 ^= arr[i];
		}
		else
		{
			*pnum2 ^= arr[i];
		}
	}
}
int main1()
{
	int arr[] = { 1,2,3,4,5,6,1,2,3,4 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	int num1 = 0;
	int num2 = 0;
	Find(arr, sz, &num1, &num2);
	printf("%d %d",num1, num2);
	return 0;
}


int main()
{
	int year = 0;
	int month = 0;
	int days[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
	while (scanf("%d %d", &year, &month) != EOF)
	{
		int day = days [month-1];
		if (((year % 4 == 0) && (year % 100 != 0)) || year % 400 == 0)
		{
			if (month == 2)
				day += 1;
		}
		printf("%d\n", day);
	}
	return 0;
}